﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using Web.Models;

namespace Web
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new HandleErrorAttribute());
        }

        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            //Account
            routes.MapRoute("Account1", "account/login", new { controller = "Account", action = "Login" });
            routes.MapRoute("Account2", "account/register",new { controller = "Account", action = "Register" });
            routes.MapRoute("Account3", "account/logout", new { controller = "Account", action = "Logout" });

            //Public
            routes.MapRoute("Public1", "", new { controller = "Public", action = "Start" });
            routes.MapRoute("Public2", "contact", new { controller = "Public", action = "Contact" });
            routes.MapRoute("Public3", "discounts", new { controller = "Public", action = "Discounts" });
            routes.MapRoute("Public4", "regulations", new { controller = "Public", action = "Regulations" });
            routes.MapRoute("Public5", "locations/{page}", new { controller = "Public", action = "Locations", page = UrlParameter.Optional });

            //Movies
            routes.MapRoute("MoviesRanks", "movies/more/ranks", new { controller = "Movies", action = "Ranks" });
            routes.MapRoute("MoviesSearch", "movies/more/search", new { controller = "Movies", action = "Search"});
            routes.MapRoute("MoviesList", "movies/parameters/{kindId}/{size}/{movieItemOrder}/{orderDirection}/{page}", new
            {
                controller = "Movies",
                action = "Index",
                kindId = 0,
                size = MovieListViewModel.SizeBig,
                movieItemOrder = MovieListViewModel.SortByAddingDate,
                orderDirection = MovieListViewModel.Descending,
                page = 1
            });
            routes.MapRoute("MovieDetails", "movie/{guid}/details/{page}", new { controller = "Movies", action = "Details", page=1});
            routes.MapRoute("MovieCopies", "movie/{guid}/copies", new { controller = "Movies", action = "CopiesInLocation", guid="" });
            routes.MapRoute("MovieVotes", "movie/{guid}/vote/{mark}", new { controller = "Movies", action = "Vote", mark = 0});
            routes.MapRoute("MovieCommentDelete", "movie/{guid}/comments/{commentGuid}/delete", new { controller = "Movies", action = "DeleteComment" });
            routes.MapRoute("MovieRent", "movie/{guid}/rent/{discGuid}", new { controller = "Movies", action = "Rent", guid = "", discGuid =""});
            

            //Customers            
            routes.MapRoute("Customers1", "customers", new { controller = "Customers", action = "Index" });
            routes.MapRoute("CustomerSelectAgency", "customers/selectAgency/{agencyId}", new { controller = "Customers", action = "SelectAgency", agencyId=0 });
            routes.MapRoute("Customers2", "customers/settings", new { controller = "Customers", action = "Settings" });
            routes.MapRoute("CustomerAccountHistory", "customers/history/{page}", new { controller = "Customers", action = "History", page = 1 });
            routes.MapRoute("CustomerRentHistory", "customers/rent/history/{page}", new { controller = "Customers", action = "RentHistory", page = 1 });
            routes.MapRoute("CustomerFinances", "customers/rent/finances/{page}", new { controller = "Customers", action = "RentCash", page = 1 });

            //Worksers
            routes.MapRoute("WorkersIndex", "workers", new { controller = "Workers", action = "Index" });

            routes.MapRoute("WorkersLocationList", "workers/locations/{page}", new { controller = "Workers", action = "Locations", page = UrlParameter.Optional});
            routes.MapRoute("WorkersLocationAdd", "workers/location/new", new { controller = "Workers", action = "LocationAdd" });
            routes.MapRoute("WorkersLocationDelete", "workers/location/{id}/delete", new { controller = "Workers", action = "LocationDelete" });
            routes.MapRoute("WorkersLocationUpdate", "workers/location/update", new { controller = "Workers", action = "LocationUpdate" });
            routes.MapRoute("WorkersSettings", "workers/events/{page}", new { controller = "Workers", action = "Events", page = 1 });

            routes.MapRoute("WorkersUserList", "workers/users/list/{page}", new { controller = "Workers", action = "Users", page = 1 });
            routes.MapRoute("WorkersUserNewEmployee", "workers/users/newEmployee", new { controller = "Workers", action = "NewEmployee" });
            routes.MapRoute("WorkersUserDelete", "workers/user/{userGuid}/delete", new { controller = "Workers", action = "UserDelete", userGuid = "" });
            routes.MapRoute("WorkersUserEdit", "workers/user/{userGuid}/edit", new { controller = "Workers", action = "UserEdit", userGuid = "" });

            routes.MapRoute("WorkersListHires", "workers/hires/current", new { controller = "Workers", action = "CurrentHires", page = 1 });
            routes.MapRoute("WorkersNewHire", "workers/hires/all", new { controller = "Workers", action = "AllHires", page = 1 });
            routes.MapRoute("WorkersReturnDisc", "workers/hire/{hireGuid}/return", new { controller = "Workers", action = "ReturnHiredDisc", hireGuid = "" });
            routes.MapRoute("WorkersFinances", "workers/finances", new { controller = "Workers", action = "Finances" });

            routes.MapRoute("WorkersMoviesList", "workers/movies/list/{itemType}/{page}", new { controller = "Workers", action = "Movies", itemType = Helper.ListItemType.Small, page = 1 });
            routes.MapRoute("WorkersMoviesNew", "workers/movies/new", new { controller = "Workers", action = "MovieAdd" });
            routes.MapRoute("WorkersMoviesEdit", "workers/movies/{guid}/edit", new { controller = "Workers", action = "MovieEdit" });
            routes.MapRoute("WorkersMoviesDelete", "workers/movies/{guid}/delete", new { controller = "Workers", action = "MovieDelete" });
            routes.MapRoute("WorkersMovieCopies", "workers/movies/{guid}/copies", new { controller = "Workers", action = "MovieCopies", guid = "" });
            routes.MapRoute("WorkersMovieCopiesInLocation", "workers/movies/{guid}/copies/location/{agencyId}", new { controller = "Workers", action = "MovieCopiesInLocation", agencyId = 0 });
            routes.MapRoute("WorkersMovieCopiesInLocationDoAction", "workers/movies/{guid}/copies/location/{agencyId}/disc/{discGuid}/action/{actionType}",
                new { controller = "Workers", action = "MovieCopiesInLocationDoAction", agencyId = 0, discGuid = "", actionType="activate" });
            routes.MapRoute("WorkersMovieCategoriesList", "workers/movies/categories", new { controller = "Workers", action = "MoviesCategories" });
            routes.MapRoute("WorkersMovieCategoriesNew", "workers/movies/categories/new", new { controller = "Workers", action = "MoviesCategoryAdd" });
            routes.MapRoute("WorkersMovieCategoriesEdit", "workers/movies/categories/{id}/edit", new { controller = "Workers", action = "MoviesCategoryEdit" });
            routes.MapRoute("WorkersMovieCategoriesDelete", "workers/movies/categories/{id}/delete", new { controller = "Workers", action = "MoviesCategoryDelete" });
                        
            routes.MapRoute("WorkerContentContact", "workers/content/contact", new { controller = "Workers", action = "EditContact" });
            routes.MapRoute("WorkerContentPromotions", "workers/content/promotions", new { controller = "Workers", action = "EditPromotions" });
            routes.MapRoute("WorkerContentRules", "workers/content/rules", new { controller = "Workers", action = "EditRules" });
            routes.MapRoute("WorkerContentSettings", "workers/content/settings", new { controller = "Workers", action = "EditSettings" });

            //routes.MapRoute(
            //    "Default", // Route name
            //    "{controller}/{action}/{id}", // URL with parameters
            //    new { controller = "Public", action = "Index", id = UrlParameter.Optional } // Parameter defaults
            //);

        }

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);
        }
    }
}